<?php
	
	class LoginView {
		
		private $login = "login";
		private $logout = "logout";
		private $passWord = "passWord";
		private $regButton = "regButton";
		private $rememberMe = "rememberMe";
		private $userName = "userName";
		
		//Funktioner för att skriva ut "formuläret".
		public function DoLoginBox() {
			return "
			<form method='post'>
					<p class='text'>Username:</p>
					<p class='box'><input type='text' name='$this->userName' /></p>
					<p class='text'>Password:</p>
					<p class='box'><input type='password' name='$this->passWord' /></p>
					<div id='divCheckBox'>
						<input type='checkbox' name='$this->rememberMe' value='rememberMe' class='checkBox' id='checkBox' />
						<label>Remember me</label>
					</div>
					<p><input type='submit' value='Log in' name='$this->login' class='button'></p>
			</form>";
		}
		
		public function DoLogoutBox() {
			
			return "
			<div id='divLogout'>
				<p>Hejhejehje, du är inloggad.</p>
				<form method='post' id='formLogout'>
					<button name='$this->logout' class='button'>Log out</button>
				</form>
			</div>";
		}
		
		public function CantLogin() {
			return "
				<div id='wrongDiv'>
					<p class='wrongMessage'>Wrong username or password.</p>
				</div>";
		}
		
		//Funktioner som returnerar användarnamnet och lösenordet.
		public function GetUserName() {		
			if (isset($_POST[$this->userName]) == true) {
				return $_POST[$this->userName];
			}	
			return false;
		}
		
		public function GetPassword() {
			if (isset($_POST[$this->passWord]) == true) {
				return $_POST[$this->passWord];
			}		
			return false;
		}
			
		//Funktion som sätter kakorna.
		public function setCookies() {	
			setcookie($this->userName, $this->GetUserName(), time() + 60*60*24*365);
			$_COOKIE[$this->userName] = true;
			
			setcookie($this->passWord, md5($this->GetPassword()), time() + 60*60*24*365);
			$_COOKIE[$this->passWord] = true;
		}
		
		public function unsetCookies() {
			setcookie($this->userName, $this->GetUserName(), time() - 3600);		
			unset($_COOKIE[$this->userName]);
			
			setcookie($this->passWord, $this->GetPassword(), time() - 3600);
			unset($_COOKIE[$this->passWord]);
		}
		
		//Funktion som returnerar Kakooorna.
		public function GetCookieUser() {
			if (isset($_COOKIE[$this->userName])) {
				return $_COOKIE[$this->userName] = true;
			}	
			return false;
		}

		public function GetCookiePass() {
			if (isset($_COOKIE[$this->passWord])) {
				return $_COOKIE[$this->passWord] = true;
			}	
			return false;
		}
		
		//Kollar om knapparna login eller logout har tryckts/remember me icheckad.
		public function TriedToLogin() {
			if (isset($_POST[$this->login]) == true) {
				return true;
			} else if (isset($_COOKIE[$this->userName])) {
				return true;
			}
			return false;
		}
		
		public function TriedToLogOut() {
			if (isset($_POST[$this->logout]) == true) {
				return true;
			}		
			return false;
		}
		
		public function RememberMe() {
			if (isset($_POST[$this->rememberMe]) == true) {
				return true;
			}
			return false;
		}
		
		public function RegButton() {
			if (isset($_POST[$this->regButton]) == true) {
				return true;
			}		
			return false;
		}
	}
